package com.example.zhangxin.myhuatuob2b.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zhangxin.myhuatuob2b.R;
import com.example.zhangxin.myhuatuob2b.activity.GoodsDetailsActivity;
import com.example.zhangxin.myhuatuob2b.activity.SubjectWebActivity;
import com.example.zhangxin.myhuatuob2b.bean.HomeGoodsList;
import com.example.zhangxin.myhuatuob2b.utils.URL;

import org.xutils.x;

import java.util.ArrayList;

/**
 * Created by ZhangXin on 2016/10/12.
 */

public class HomeGoodsMyGridViewListAdapter extends BaseAdapter{
    private Context context;
    private ArrayList<HomeGoodsList> data;

    public HomeGoodsMyGridViewListAdapter(Context context, ArrayList<HomeGoodsList> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (null == convertView) {
            convertView = View.inflate(context,R.layout.tab_home_item_goods_gridview_item, null);
            holder = new ViewHolder();
            holder.ImageViewImagePic01 = (ImageView) convertView.findViewById(R.id.ImageViewImagePic01);
            holder.TextViewTitle = (TextView) convertView.findViewById(R.id.TextViewTitle);
            holder.TextViewPrice = (TextView) convertView.findViewById(R.id.TextViewPrice);
            holder.TextViewGuige = (TextView) convertView.findViewById(R.id.TextViewGuige);
            holder.TextViewFactory = (TextView) convertView.findViewById(R.id.TextViewFactory);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        HomeGoodsList bean = data.get(position);

        holder.TextViewTitle.setText(bean.getGoods_name());
        holder.TextViewGuige.setText(bean.getGoods_guige());
        holder.TextViewFactory.setText(bean.getGoods_factory());
        holder.TextViewPrice.setText("￥" + bean.getGoods_promotion_price());
        x.image().bind(holder.ImageViewImagePic01,bean.getGoods_image());

        return convertView;
    }

    class ViewHolder {
        ImageView ImageViewImagePic01;  //药品缩略图
        TextView TextViewTitle;         //药品名字
        TextView TextViewPrice;         //药品价钱
        TextView TextViewGuige;         //药品规格
        TextView TextViewFactory;         //药品生产厂家
    }



}
